# 09/10/2022 ;
# coefficient plots (Figure 4) ;
library(bayesplot)
library(brms)
library(ggpubr)
library(rstan)
library(tidyverse)

theme_set(theme_tufte())

#-------------------------------------------------------------------------------
# LOAD MULTIVARIATE LINEAR RESULTS DATASET ;
load("MULTI_METRIC.RData")
#-------------------------------------------------------------------------------

# PAY ;
plot_pay <- mcmc_intervals(rc_pay, pars=c("b_sbeqsoc",
                                          "b_sbprvpv",
                                          "b_sblwcoa",
                                          "b_sblazy",
                                          "b_sbbsntx",
                                          "b_sbstrec",
                                          "b_pplhlp",
                                          "b_ppltrst",
                                          "b_pplfair",
                                          "b_lrscale",
                                          "b_subj_unemp",
                                          "b_prev_unemp",
                                          "b_cont_unemp",
                                          "b_edu_bmask.L",
                                          "b_edu_bmask.Q",
                                          "b_edu_bmask.C",
                                          "b_income",
                                          "b_female",
                                          "b_age2",
                                          "b_age",
                                          "b_vignette4",
                                          "b_vignette3",
                                          "b_vignette1"))

plot_pay <- plot_pay + ggtitle("S1: geringere Bezahlung") + 
  scale_y_discrete(label=c(b_vignette1="T1: 20-25 Jahre",
                                    b_vignette3="T3: 50-59 Jahre", 
                                    b_vignette4="T4: alleinerziehend",
                                    b_age="Alter",
                                    b_age2="Alter (quad.)",
                                    b_female="weiblich",
                                    b_edu_bmask.L="Bildung (sehr hoch)",
                                    b_edu_bmask.Q="Bildung (hoch)",
                                    b_edu_bmask.C="Bildung (gering)",
                                    b_income="Einkommen",
                                    b_cont_unemp="arbeitslos (gegenwärtig)",
                                    b_prev_unemp="arbeitslos (früher)",
                                    b_subj_unemp="arbeitslos (Risiko)",
                                    b_pplfair="Menschen: fair",
                                    b_ppltrst="Menschen: Vertrauen",
                                    b_pplhlp="Menschen: hilfsbereit",
                                    b_lrscale="links-rechts",
                                    b_sbbsntx="SV: zu teuer für Firmen",
                                    b_sbeqsoc="SV: egalitäre Gesellschaft",
                                    b_sblazy="SV: faul",
                                    b_sblwcoa="SV: weniger kümmern",
                                    b_sbprvpv="SV: verhindert Armut",
                                    b_sbstrec="SV: Belastung der Wirtschaft"
                                    ), 
                            limits=c("b_sbeqsoc",
                                     "b_sbprvpv",
                                     "b_sblwcoa",
                                     "b_sbbsntx",
                                     "b_sblazy",
                                     "b_sbstrec",
                                     "b_pplhlp",
                                     "b_ppltrst",
                                     "b_pplfair",
                                     "b_lrscale",
                                     "b_subj_unemp",
                                     "b_prev_unemp",
                                     "b_cont_unemp",
                                     "b_edu_bmask.L",
                                     "b_edu_bmask.Q",
                                     "b_edu_bmask.C",
                                     "b_income",
                                     "b_female",
                                     "b_age2",
                                     "b_age",
                                     "b_vignette4",
                                     "b_vignette3",
                                     "b_vignette1") )

#-------------------------------------------------------------------------------
# EDU ;
plot_edu <- mcmc_intervals(rc_edu, pars=c("b_sbeqsoc",
                                          "b_sbprvpv",
                                          "b_sblwcoa",
                                          "b_sblazy",
                                          "b_sbbsntx",
                                          "b_sbstrec",
                                          "b_pplhlp",
                                          "b_ppltrst",
                                          "b_pplfair",
                                          "b_lrscale",
                                          "b_subj_unemp",
                                          "b_prev_unemp",
                                          "b_cont_unemp",
                                          "b_edu_bmask.L",
                                          "b_edu_bmask.Q",
                                          "b_edu_bmask.C",
                                          "b_income",
                                          "b_female",
                                          "b_age2",
                                          "b_age",
                                          "b_vignette4",
                                          "b_vignette3",
                                          "b_vignette1"))


plot_edu <- plot_edu + ggtitle("S2: geringre Qualifikation") + 
  scale_y_discrete(label=c(b_vignette1="",
                                                 b_vignette3="", 
                                                 b_vignette4="",
                                                 b_age="",
                                                 b_age2="",
                                                 b_female="",
                                                 b_edu_bmask.L="",
                                                 b_edu_bmask.Q="",
                                                 b_edu_bmask.C="",
                                                 b_income="",
                                                 b_cont_unemp="",
                                                 b_prev_unemp="",
                                                 b_subj_unemp="",
                                                 b_pplfair="",
                                                 b_ppltrst="",
                                                 b_pplhlp="",
                                                 b_lrscale="",
                                                 b_sbbsntx="",
                                                 b_sbeqsoc="",
                                                 b_sblazy="",
                                                 b_sblwcoa="",
                                                 b_sbprvpv="",
                                                 b_sbstrec=""), 
                                      limits=c("b_sbeqsoc",
                                                "b_sbprvpv",
                                                "b_sblwcoa",
                                                "b_sbbsntx",
                                                "b_sblazy",
                                                "b_sbstrec",
                                                "b_pplhlp",
                                                "b_ppltrst",
                                                "b_pplfair",
                                                "b_lrscale",
                                                "b_subj_unemp",
                                                "b_prev_unemp",
                                                "b_cont_unemp",
                                                "b_edu_bmask.L",
                                                "b_edu_bmask.Q",
                                                "b_edu_bmask.C",
                                                "b_income",
                                                "b_female",
                                                "b_age2",
                                                "b_age",
                                                "b_vignette4",
                                                "b_vignette3",
                                                "b_vignette1") )



# UNP ;
plot_unp <- mcmc_intervals(rc_unp, pars=c("b_sbeqsoc",
                                          "b_sbprvpv",
                                          "b_sblwcoa",
                                          "b_sblazy",
                                          "b_sbbsntx",
                                          "b_sbstrec",
                                          "b_pplhlp",
                                          "b_ppltrst",
                                          "b_pplfair",
                                          "b_lrscale",
                                          "b_subj_unemp",
                                          "b_prev_unemp",
                                          "b_cont_unemp",
                                          "b_edu_bmask.L",
                                          "b_edu_bmask.Q",
                                          "b_edu_bmask.C",
                                          "b_income",
                                          "b_female",
                                          "b_age2",
                                          "b_age",
                                          "b_vignette4",
                                          "b_vignette3",
                                          "b_vignette1"))


plot_unp <- plot_unp + ggtitle("S3: gemeinnützige Arbeit") + 
  scale_y_discrete(label=c(b_vignette1="",
                                                b_vignette3="", 
                                                b_vignette4="",
                                                b_age="",
                                                b_age2="",
                                                b_female="",
                                                b_edu_bmask.L="",
                                                b_edu_bmask.Q="",
                                                b_edu_bmask.C="",
                                                b_income="",
                                                b_cont_unemp="",
                                                b_prev_unemp="",
                                                b_subj_unemp="",
                                                b_pplfair="",
                                                b_ppltrst="",
                                                b_pplhlp="",
                                                b_lrscale="",
                                                b_sbbsntx="",
                                                b_sbeqsoc="",
                                                b_sblazy="",
                                                b_sblwcoa="",
                                                b_sbprvpv="",
                                                b_sbstrec=""), 
                                        limits=c("b_sbeqsoc",
                                                 "b_sbprvpv",
                                                 "b_sblwcoa",
                                                 "b_sbbsntx",
                                                 "b_sblazy",
                                                 "b_sbstrec",
                                                 "b_pplhlp",
                                                 "b_ppltrst",
                                                 "b_pplfair",
                                                 "b_lrscale",
                                                 "b_subj_unemp",
                                                 "b_prev_unemp",
                                                 "b_cont_unemp",
                                                 "b_edu_bmask.L",
                                                 "b_edu_bmask.Q",
                                                 "b_edu_bmask.C",
                                                 "b_income",
                                                 "b_female",
                                                 "b_age2",
                                                 "b_age",
                                                 "b_vignette4",
                                                 "b_vignette3",
                                                 "b_vignette1") )

plot_all <- ggarrange(plot_pay, plot_edu, plot_unp, nrow=1)

ggsave("FIG_4.png", plot=last_plot(), width=18, height=9)
